<include file="common/header_lixin" title="矿机市场" />
<div class="page">
    <div class="page-hd">
        <div class="header bor-1px-b">
            <div class="header-left">
                <a href="javascript:history.go(-1)" class="left-arrow"></a>
            </div>
            <div class="header-title">矿机市场</div>
            <div class="header-right">
                <a href="#"></a>
            </div>
        </div>
    </div>

    <div class="page-bd">
        <!-- 页面内容-->
        <div class="weui-tab">
            <div class="weui-navbar">
                <a class="weui-navbar__item weui-bar__item--on"  id="status1" status="1"  rel="1" page="1" href="#tab1">
                    正常矿机
                </a>
                <a class="weui-navbar__item" id="status2" rel="2" page="1" status="2"  onClick="init2()" href="#tab2">
                    到期矿机
                </a>
            </div>
            <div class="weui-tab__bd">
                <div id="tab1" class="weui-tab__bd-item weui-tab__bd-item--active">
                    <div class="weui-panel rmtj_panel">
                        <div class="weui-panel__bd">
                            <div class="weui-cells border-none" id="one">

                            </div>
                        </div>
                    </div>
                   <!-- <div class="weui-btn-area">
                        <a href="javascript:;" onClick="allProfit()" class="weui-btn weui-btn_primary">一键领取</a>
                    </div>-->
                   <!-- <div class="weui-btn-area">
                        <a href="javascript:;" onClick="allStart()" class="weui-btn weui-btn_primary">一键开启</a>
                    </div>-->
                </div>
                <div id="tab2" class="weui-tab__bd-item">
                    <div class="weui-panel rmtj_panel">
                        <div class="weui-panel__bd">
                            <div class="weui-cells border-none" id="two">

                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <include file="common/footer_lixin"/>
</div>
<script>
    $(function() {
        FastClick.attach(document.body);
    });
</script>
<script>
$.toast.prototype.defaults.duration = 1200;
var ajax_status1 = false;
var ajax_status2 = false;
init();

function init(){

    if (ajax_status1) return;
    ajax_status1 = true;
    loadlist(1,1);
}
function init2(){
    if ($('#status2').attr('page') != 1) {return ;}
    // if ($('#status2').attr('status') != 1) {return ;}

    if (ajax_status2) return;
    $('#status2').attr('status',2)
    ajax_status2 = true;
    loadlist(1,2);
}

// 加载更多商品
$('#tab1').infinite(30).on("infinite", function() {
    if (ajax_status1) return;
    ajax_status1 = true;

    var p = $('#status1').attr('page');
    p++;
    $('#status1').attr('page',p)
    loadlist(p,1);

});
$('#tab2').infinite(30).on("infinite", function() {
    if (ajax_status2) return;
    ajax_status2 = true;
    var p = $('#status2').attr('page');
    p++;
    $('#status2').attr('page',p)
    loadlist(p,2);
});

    function loadlist(p,status){
        $.ajax({
            url : "/Acc/Mining/ajaxMyMiner/p/"+ p,
            type:'post',
            dataType:'json',
            data:{'p': p,'status' : status},
            success:function(data){
                var subject = '';
                if (status == 1) {
                    subject = 'one';
                } else if(status == 2){
                    subject = 'two';
                }
                if (p == 1) {
                    // $('#'+subject).empty();
                }

               if($.trim(data)==''){
                    $.toast("无更多数据", "text");
                }else{
                    $('#'+subject).append(data);
                    ajax_status1 = false;
                    ajax_status2 = false;
                }
            },
            error:function(){
                $.toptip('网络异常，请稍后再试')
            }
        })
    }
    var ajax_status3 = false;
    function profit(id){
        if (ajax_status3) {return ;};
         ajax_status3 = true;
        $.ajax({
            url : "/Acc/Mining/profit/",
            type:'post',
            dataType:'json',
            data:{'id': id},
            success:function(data){
                if (data.code == 1) {
                    $.toast(data.msg, function() {
                        window.location.reload();
                    });
                } else {
                    $.toptip(data.msg, 'error')
                }
                ajax_status3 = false;
            },
            error:function(){
                $.toptip('网络异常，请稍后再试')
            }
        })
    }
    var ajax_status4 = false;
    function allProfit(id){
        if (ajax_status4) {return ;};
         ajax_status4 = true;
        $.ajax({
            url : "/Acc/Mining/allProfit",
            type:'post',
            dataType:'json',
            data:{'id': id},
            success:function(data){
                if (data.code == 1) {
                    window.location.reload()
                    $.toptip(data.data);
                } else {
                    $.toptip(data.msg, 'error')
                }
                ajax_status4 = false;
            },
            error:function(){
                $.toptip('网络异常，请稍后再试')
            }
        })
    }
    var ajax_status5 = false;
    function allStart(id){
        if (ajax_status5) {return ;};
            ajax_status5 = true;
        $.ajax({
            url : "/Acc/Mining/allStart",
            type:'post',
            dataType:'json',
            data:{'id': id},
            success:function(data){
                if (data.code == 1) {
                    window.location.reload()
                    $.toptip(data.data);
                } else {
                    $.toptip(data.msg, 'error')
                }
                ajax_status5 = false;
            },
            error:function(){
                $.toptip('网络异常，请稍后再试')
            }
        })
    }
    function upgrade(id){
        $.ajax({
            url : "/Acc/Mining/upgrade/",
            type:'post',
            dataType:'json',
            data:{'id': id},
            success:function(data){
                if (data.code == 1) {
                    $.toast(data.msg, function() {
                        window.location.reload();
                    });
                } else {
                    $.toptip(data.msg, 'error')
                }
                ajax_status3 = false;
            },
            error:function(){
                $.toptip('网络异常，请稍后再试')
            }
        })
    }
</script>
</body>
</html>
